package ynu.edu.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import ynu.edu.common.entity.LogicEntity;

import javax.persistence.*;

@Entity
@Getter
@Setter
public class LineItem extends LogicEntity {
    @Column
    private Integer quantity;

    @OneToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name = "shopItem_id")
    @JsonIgnoreProperties("lineItems")
    private ShopItem shopItem;

    @ManyToOne(cascade = {CascadeType.MERGE},fetch = FetchType.EAGER)
    @JoinColumn(name = "order_id")
    @JsonIgnoreProperties("lineItems")
    private Order order;

    @JsonIgnore
    public Double getLineItemPrice() {
        return  shopItem.getShopItemPrice() * quantity;
    }
}
